package hr.ctg.web.parser;

import org.htmlparser.Tag;
import org.htmlparser.tags.LinkTag;
import org.htmlparser.visitors.UrlModifyingVisitor;

public class LinkUrlModifyingVisitor extends UrlModifyingVisitor {
	private final String linkPrefix;

	public LinkUrlModifyingVisitor(final String linkPrefix) {
		super("");
		this.linkPrefix = linkPrefix;
	}

	@Override
	public void visitTag(final Tag tag) {
		if (tag instanceof LinkTag) {
			final LinkTag lTag = (LinkTag) tag;
			lTag.setAttribute("target", "_blank");
			lTag.setAttribute("class", "new-window");
			lTag.setAttribute("href", linkPrefix + lTag.getAttribute("href"));
		}
		super.visitTag(tag);
	}
}
